﻿@{
    ViewBag.Title = "EmployeeTable";
}
<script type="text/javascript">
    function UpdateRole(e, id) {

        var temp = $('#userRole-' + id).val();
        if (temp != '8bb02bd4-ed14-4750-ad84-f55f10cc6c75') {
            $.ajax({
                type: "POST",
                url: "/EmployeeRegistration/updateEmployeeTable?EmployeeId=" + id + "&IsActive=1&UserRoleId=" + temp,
                success: function () {
                    var oTable2 = $('#example').dataTable();
                    oTable2.fnDraw();
                }
            });
        }
        else {
            alert('Please select a role for this user!');
        }

    }
    function UpdateRoleExistingUser(e, id) {

        var temp = $('#userRole-' + id).val();
        if (temp != '8bb02bd4-ed14-4750-ad84-f55f10cc6c75') {
            $.ajax({
                type: "POST",
                url: "/EmployeeRegistration/updateEmployeeTable?EmployeeId=" + id + "&IsActive=2&UserRoleId=" + temp,
                success: function () {
                    var oTable2 = $('#example').dataTable();
                    oTable2.fnDraw();
                }
            });
        }
        else if (temp == '8bb02bd4-ed14-4750-ad84-f55f10cc6c75') {
            var result = confirm('Are you sure want to Deactivete this user?');
            if (result == true) {
                $.ajax({
                    type: "POST",
                    url: "/EmployeeRegistration/updateEmployeeTable?EmployeeId=" + id + "&IsActive=0&UserRoleId=" + temp,
                    success: function () {
                        var oTable2 = $('#example').dataTable();
                        oTable2.fnDraw();
                    }
                });
            }
        }

    }

    $(document).ready(function () {
        var oTables = $('#example').dataTable({
            "bServerSide": true,
            "sAjaxSource": "/EmployeeRegistration/AjaxEmployeeList",
            "bProcessing": true,
            "sPaginationType": "full_numbers",
            "aoColumns":
[
{ "sName": "First Name", "sTitle": "First Name", "bVisible": true, "bSortable": true, "fnRender": function (oObj) { return oObj.aData[0]; } },
{ "sName": "Last Name", "sTitle": "Last Name", "bVisible": true, "bSortable": true, "fnRender": function (oObj) { return oObj.aData[1]; } },
{ "sName": "Email", "sTitle": "Email", "bVisible": true, "bSortable": true, "fnRender": function (oObj) { return oObj.aData[2]; } },
{ "sName": "City", "sTitle": "City", "bVisible": true, "bSortable": true, "fnRender": function (oObj) { return oObj.aData[3]; } },
{ "sName": "Contact", "sTitle": "Contact", "bVisible": true, "bSortable": true, "fnRender": function (oObj) { return oObj.aData[4]; } },
{ "sName": "Employee ID", "sTitle": "Employee ID", "bVisible": true, "bSortable": true, "fnRender": function (oObj) { return oObj.aData[5]; } },
{ "sName": "Role", "sTitle": "Current Role", "bVisible": true, "bSortable": true, "fnRender": function (oObj) { return oObj.aData[6]; } },
{ "sName": "AssignRole", "sTitle": "AssignRole", "bVisible": true, "bSortable": true, "fnRender": function (oObj) { return oObj.aData[7]; } },
{ "sName": "IsActive", "sTitle": "IsActive", "bVisible": true, "bSortable": true, "fnRender": function (oObj) { return oObj.aData[8]; } },

]
        });
        oTables = $('#example').dataTable();





    });
</script>
<div class="grid_10">
    <div class="box round first grid">
        <h2>
            Employee List</h2>
        <div class="block">
           
            <table class="data display datatable" id="example">
                <thead>
                    <tr>
                        <th>
                        </th>
                        <th>
                        </th>
                        <th>
                        </th>
                        <th>
                        </th>
                        <th>
                        </th>
                        <th>
                        </th>
                        <th>
                        </th>
                        <th>
                        </th>
                        <th>
                        </th>
                    </tr>
                </thead>
            </table>
        </div>
    </div>
    <a href='#'>
        <label id="lbl1">
        </label>
    </a>
</div>
